/* 游戏单位 */

var ENUM_UNITTYPE = {
    bullet:0,
    zombie:1,
    hero:2
}

var ENUM_UNITSTATUS = {
    idle:0,
    wait:1,
    runing:2,
    dead:3
}

var FightUnit = function (){

    var self = this;
    self.property = {
        id:"",
        hp:0,
        speed:0,
        utype:0
    }

    self.READER = new BTNTreeReader();

    //生成属性
    for (var proname in self.property){
        self["get" + proname] = (function(){
            var _tmp = proname;
            return function(){
                return self.property[_tmp];
            }
        })
        self["set" + proname] = (function(val){
            var _tmp = proname;
            return function(){
                self.property[_tmp] = val;
            }
        })
    }

    self.init = function(proeprty){
        //property 
        var onlyid = new Date().getTime();
        self.setid(onlyid);
        self.sethp(100);
        self.setspeed(10);
        self.setutype(ENUM_UNITTYPE["zombie"]);

        //behavior tree
        cc.loader.loadJson("src/fight/btn_zombie.json", function(err, dic){
            self._btnroot = self.READER.parse(dic, self)
        })

        cc.log("chk the event mgr-->>",  CEventMgr);
        CEventMgr.Instance().addEventListener(CEVENT_ID["FUNIT_WAIT"], function(){
            cc.log("do do do ");
        })
    }

    self.process = function(dt){
        if (self._btnroot){
            if (self._btnroot.evaluate()){
                self._btnroot.tick()
            }
        }
    }

    self.is_dead = function(){
        return self.gethp() >= 0;
    }
}

